package com.liruo.learn.spring.mvc.controller.valid;

import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;

/**
 * @Author:liruo
 * @Date:2023-05-08-21:32:56
 * @Desc
 */
@RestController
@Slf4j
@RequestMapping("/valid-validated")
public class ValidAndValidatedController {
    @Validated
    @GetMapping("/validated/bean")
    public @NotNull ValidBean validatedBean( ValidBean validBean){
        log.info("bean {}", validBean);
        return null;
    }
    @Validated
    @GetMapping("/validated/common")
    public @NotNull String validatedCommon(@NotNull String notNull, @NotBlank String notBlank, @NotEmpty String notEmpty, @NotEmpty ArrayList<String> listNotEmpty1) {
        log.info("common, {} {} {} {}", notNull, notBlank, notEmpty, listNotEmpty1);
        return null;
    }

    @GetMapping("/valid/bean")
    public @NotNull ValidBean validBean(@Valid ValidBean validBean){
        log.info("bean {}", validBean);
        return null;
    }
    @GetMapping("/valid/common")
    public @NotNull String validCommon(@Valid @NotNull String notNull, @NotBlank String notBlank, @NotEmpty String notEmpty, @NotEmpty ArrayList<String> listNotEmpty1) {
        log.info("common, {} {} {} {}", notNull, notBlank, notEmpty, listNotEmpty1);
        return null;
    }
}

